package com.ruoyi.record.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.record.domain.IncomeExpenseRecord;
import com.ruoyi.record.service.IIncomeExpenseRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 账户概况Controller
 * 
 * @author ruoyi
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/record")
public class IncomeExpenseRecordController extends BaseController
{
    @Autowired
    private IIncomeExpenseRecordService incomeExpenseRecordService;

    /**
     * 查询账户概况列表
     */
    @RequiresPermissions("record:record:list")
    @GetMapping("/list")
    public TableDataInfo list(IncomeExpenseRecord incomeExpenseRecord)
    {
        startPage();
        List<IncomeExpenseRecord> list = incomeExpenseRecordService.selectIncomeExpenseRecordList(incomeExpenseRecord);
        return getDataTable(list);
    }

    /**
     * 导出账户概况列表
     */
    @RequiresPermissions("record:record:export")
    @Log(title = "账户概况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IncomeExpenseRecord incomeExpenseRecord)
    {
        List<IncomeExpenseRecord> list = incomeExpenseRecordService.selectIncomeExpenseRecordList(incomeExpenseRecord);
        ExcelUtil<IncomeExpenseRecord> util = new ExcelUtil<IncomeExpenseRecord>(IncomeExpenseRecord.class);
        util.exportExcel(response, list, "账户概况数据");
    }

    /**
     * 获取账户概况详细信息
     */
    @RequiresPermissions("record:record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(incomeExpenseRecordService.selectIncomeExpenseRecordById(id));
    }

    /**
     * 新增账户概况
     */
    @RequiresPermissions("record:record:add")
    @Log(title = "账户概况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IncomeExpenseRecord incomeExpenseRecord)
    {
        return toAjax(incomeExpenseRecordService.insertIncomeExpenseRecord(incomeExpenseRecord));
    }

    /**
     * 修改账户概况
     */
    @RequiresPermissions("record:record:edit")
    @Log(title = "账户概况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IncomeExpenseRecord incomeExpenseRecord)
    {
        return toAjax(incomeExpenseRecordService.updateIncomeExpenseRecord(incomeExpenseRecord));
    }

    /**
     * 删除账户概况
     */
    @RequiresPermissions("record:record:remove")
    @Log(title = "账户概况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(incomeExpenseRecordService.deleteIncomeExpenseRecordByIds(ids));
    }
}
